package net.zjitc.common;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;

import java.io.Serializable;

/**
 * @Author 毛钰深
 * @Create 2021/12/27 10:22
 */

@Data
public class ResponseResult<T>  {
    @JsonInclude(JsonInclude.Include.ALWAYS)
    private T data;
    private Meta meta;

    public ResponseResult(T data, Meta meta) {
        this.data = data;
        this.meta = meta;
    }

    public ResponseResult() {
        this.meta=new Meta();
    }

    public void setSuccess(){
        meta.setStatus(ResponseCode.SUCCESS.getCode());
        meta.setMsg(ResponseCode.SUCCESS.getMessage());
    }
    public void setSuccess(T data){
        meta.setStatus(ResponseCode.SUCCESS.getCode());
        meta.setMsg(ResponseCode.SUCCESS.getMessage());
        this.data=data;
    }
    public void setSuccess(String msg){
        meta.setStatus(ResponseCode.SUCCESS.getCode());
        meta.setMsg(msg);
    }
    public void setSuccess(String msg,T data){
        meta.setStatus(ResponseCode.SUCCESS.getCode());
        meta.setMsg(msg);
        this.data = data;
    }


    public void setCreated(){
        meta.setStatus(ResponseCode.CREATED.getCode());
        meta.setMsg(ResponseCode.CREATED.getMessage());
    }
    public void setCreated(String msg){
        meta.setStatus(ResponseCode.CREATED.getCode());
        meta.setMsg(msg);
    }
    public void setCreated(T data){
        meta.setStatus(ResponseCode.CREATED.getCode());
        meta.setMsg(ResponseCode.CREATED.getMessage());
        this.data = data;
    }
    public void setCreated(String msg,T data){
        meta.setStatus(ResponseCode.CREATED.getCode());
        meta.setMsg(msg);
        this.data = data;
    }

    public void setDeleted(){
        meta.setStatus(ResponseCode.DELETED.getCode());
        meta.setMsg(ResponseCode.DELETED.getMessage());
    }
    public void setDeleted(String msg){
        meta.setStatus(ResponseCode.DELETED.getCode());
        meta.setMsg(msg);
    }
    public void setDeleted(String msg,T data){
        meta.setStatus(ResponseCode.DELETED.getCode());
        meta.setMsg(msg);
        this.data = data;
    }

    public void setNotFound(){
        meta.setStatus(ResponseCode.NOT_FOUND.getCode());
        meta.setMsg(ResponseCode.NOT_FOUND.getMessage());
    }
    public void setNotFound(String msg){
        meta.setStatus(ResponseCode.NOT_FOUND.getCode());
        meta.setMsg(msg);
    }

    public void setNotFound(String msg,T data){
        meta.setStatus(ResponseCode.NOT_FOUND.getCode());
        meta.setMsg(msg);
        this.data = data;
    }
    public void setBadRequest(){
        meta.setStatus(ResponseCode.BAD_REQUEST.getCode());
        meta.setMsg(ResponseCode.BAD_REQUEST.getMessage());
    }
    public void setBadRequest(String msg){
        meta.setStatus(ResponseCode.BAD_REQUEST.getCode());
        meta.setMsg(msg);
    }

    public void setBadRequest(String msg,T data){
        meta.setStatus(ResponseCode.BAD_REQUEST.getCode());
        meta.setMsg(msg);
        this.data = data;
    }

    public void setError(){
        meta.setStatus(ResponseCode.ERROR.getCode());
        meta.setMsg(ResponseCode.ERROR.getMessage());
    }
    public void setError(String msg){
        meta.setStatus(ResponseCode.ERROR.getCode());
        meta.setMsg(msg);
    }
    public void setError(String msg,T data){
        meta.setStatus(ResponseCode.ERROR.getCode());
        meta.setMsg(msg);
        this.data = data;
    }
    public void setError(int status,String msg){
        meta.setStatus(status);
        meta.setMsg(msg);
    }
    public void setUnprocesableEntity(){
        meta.setStatus(ResponseCode.UNPROCESABLE_ENTITY.getCode());
        meta.setMsg(ResponseCode.UNPROCESABLE_ENTITY.getMessage());
    }
    public void setUnprocesableEntity(String msg){
        meta.setStatus(ResponseCode.UNPROCESABLE_ENTITY.getCode());
        meta.setMsg(msg);
    }
    public void setUnprocesableEntity(String msg,T data){
        meta.setStatus(ResponseCode.UNPROCESABLE_ENTITY.getCode());
        meta.setMsg(msg);
        this.data = data;
    }

    public void setForbidden(){
        meta.setStatus(ResponseCode.FORBIDDEN.getCode());
        meta.setMsg(ResponseCode.FORBIDDEN.getMessage());
    }
    public void setForbidden(String msg){
        meta.setStatus(ResponseCode.FORBIDDEN.getCode());
        meta.setMsg(msg);
    }

    public void setForbidden(String msg,T data){
        meta.setStatus(ResponseCode.FORBIDDEN.getCode());
        meta.setMsg(msg);
        this.data = data;
    }
}
